//
//  YCPaopaoView.m
//  YCSchool
//
//  Created by Yanglixia on 16/4/30.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  地图标注泡泡视图

#import "YCPaopaoView.h"

@interface YCPaopaoView ()

/** block */
@property (nonatomic, copy) callPhoneBtnClickBlock callBlock;

@end

@implementation YCPaopaoView

- (instancetype)initWithWithFrame:(CGRect)frame callPhoneBtnClickBlock:(callPhoneBtnClickBlock)clickBlock
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupChildView];
        self.backgroundColor = [UIColor clearColor];
        self.callBlock = clickBlock;
    }
    return self;
}

- (void)setupChildView
{
    // 背景图片
    UIImageView *bgImageView = [[UIImageView alloc] init];
    bgImageView.userInteractionEnabled = YES;
    bgImageView.image = [UIImage imageNamed:@"地址框"];
    bgImageView.backgroundColor = [UIColor clearColor];
    [self addSubview:bgImageView];
    
    // 驾校门面图
    UIImageView *iconImageView = [[UIImageView alloc] init];
    iconImageView.image = [UIImage yc_placeHolderImageForSize:CGSizeMake(63, 63)];
    [bgImageView addSubview:iconImageView];
    
    // 驾校点名称
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.text = @"一乘驾校 (金殿点)";
    nameLabel.font = [UIFont systemFontOfSize:14];
    nameLabel.textColor = [UIColor yc_colorWithUInt:0x333333];
    [bgImageView addSubview:nameLabel];
    
    // 地址
    UILabel *addressLabel = [[UILabel alloc] init];
    addressLabel.text = @"盘龙金殿水库后麦冲村7号";
    addressLabel.numberOfLines = 0;
    addressLabel.font = [UIFont systemFontOfSize:10];
    addressLabel.textColor = [UIColor yc_colorWithUInt:0x999999];
    [bgImageView addSubview:addressLabel];
    
    // 营业时间
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.text = @"周一至周末 9：00-18：00";
    timeLabel.font = [UIFont systemFontOfSize:10];
    timeLabel.textColor = [UIColor yc_colorWithUInt:0x999999];
    [bgImageView addSubview:timeLabel];
    
    // 支付方式
    UILabel *payMethodLabel = [[UILabel alloc] init];
    payMethodLabel.text = @"缴费方式 刷卡";
    payMethodLabel.font = [UIFont systemFontOfSize:10];
    payMethodLabel.textColor = [UIColor yc_colorWithUInt:0x999999];
    [bgImageView addSubview:payMethodLabel];
    
    // 打电话
    UIButton *callBtn = [[UIButton alloc] init];
    [callBtn setImage:[UIImage imageNamed:@"拨打电话"] forState:UIControlStateNormal];
    [callBtn addTarget:self action:@selector(callPhone) forControlEvents:UIControlEventTouchUpInside];
    [bgImageView addSubview:callBtn];
    
    
    [bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self);
    }];
    
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgImageView).offset(17);
        make.top.equalTo(self).offset(22);
        make.height.width.equalTo(@63);
    }];
    
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImageView.mas_right).offset(17);
        make.top.equalTo(iconImageView).offset(-5);
    }];
    
    [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImageView.mas_right).offset(17);
        make.top.equalTo(nameLabel.mas_bottom).offset(10);
        make.right.equalTo(bgImageView).offset(-17);
    }];
    
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImageView.mas_right).offset(17);
        make.top.equalTo(addressLabel.mas_bottom).offset(5);
    }];
    
    [payMethodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImageView.mas_right).offset(17);
        make.top.equalTo(timeLabel.mas_bottom).offset(11);
    }];
    
    [callBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgImageView.mas_right).offset(-15);
        make.bottom.equalTo(bgImageView).offset(-13-13);
        make.height.with.equalTo(@29);
    }];

}

- (void)callPhone
{
    !self.callBlock ? :self.callBlock(@"4000125111");//客服电话
}

@end
